package cn.stylefeng.guns.modular.hx.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.order.model.result.HxOrderPutResult;
import cn.stylefeng.guns.modular.hx.storage.entity.HxStoragePut;
import cn.stylefeng.guns.modular.hx.storage.mapper.HxStoragePutMapper;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxStoragePutDetailedParam;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxStoragePutParam;
import cn.stylefeng.guns.modular.hx.storage.model.result.rukuPositionResult;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxStoragePutResult;
import  cn.stylefeng.guns.modular.hx.storage.service.HxStoragePutService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 入库单表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2023-08-14
 */
@Service
public class HxStoragePutServiceImpl extends ServiceImpl<HxStoragePutMapper, HxStoragePut> implements HxStoragePutService {

    @Override
    public void add(HxStoragePutParam param){
        HxStoragePut entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HxStoragePutParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HxStoragePutParam param){
        HxStoragePut oldEntity = getOldEntity(param);
        HxStoragePut newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HxStoragePutResult findBySpec(HxStoragePutParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<HxStoragePutResult> findListBySpec(HxStoragePutParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(HxStoragePutParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findreturnPageBySpec(HxStoragePutParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findreturnPageBySpec(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(HxStoragePutParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HxStoragePut getOldEntity(HxStoragePutParam param) {
        return this.getById(getKey(param));
    }

    private HxStoragePut getEntity(HxStoragePutParam param) {
        HxStoragePut entity = new HxStoragePut();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<HxStoragePutResult> restfindstoragelist(HxStoragePutParam hxStoragePutParam) {
		return this.baseMapper.restfindstoragelist(hxStoragePutParam);
	}

	@Override
	public HxStoragePutResult restfindstorage(HxStoragePutParam hxStoragePutParam) {
		return this.baseMapper.restfindstorage(hxStoragePutParam);
	}


    // 入库质检信息统计

    @Override
    public LayuiPageInfo getqualityuser(HxStoragePutParam hxStoragePutParam, String condition) {
        Page pageContext = getPageContext();
        IPage qualityuser = this.baseMapper.getQualityuser(pageContext,hxStoragePutParam,condition);
        return   LayuiPageFactory.createPageInfo(qualityuser);
    }
    // 上架信息统计

    @Override
    public LayuiPageInfo shangjiauser(HxStoragePutDetailedParam hxStoragePutDetailedParam, String condition) {
        Page pageContext = getPageContext();
        IPage qualityuser = this.baseMapper.shangjiauser(pageContext,hxStoragePutDetailedParam,condition);
        return   LayuiPageFactory.createPageInfo(qualityuser);
    }

	@Override
	public List<HxStoragePutResult> restfindstoragereturnlist(HxStoragePutParam hxStoragePutParam) {
		return this.baseMapper.restfindstoragereturnlist(hxStoragePutParam);
	}

    @Override
    public List<rukuPositionResult> findrukuposition(rukuPositionResult rukuPositionResult) {
        return this.baseMapper.findrukuposition(rukuPositionResult);
    }

    @Override
    public List <HxStoragePutResult> findlistAllBySpec(HxStoragePutParam hxStoragePutParam, String condition, Long operateId) {
        List<HxStoragePutResult> arrlist = this.baseMapper.findlistAllBySpec(hxStoragePutParam,condition,operateId);
        return arrlist;
    }

    @Override
    public HxStoragePutResult count(HxStoragePutParam hxStoragePutParam, String condition, Long operateId) {
        return this.baseMapper.count(hxStoragePutParam,condition,operateId);
    }
    @Override
    public HxStoragePutResult count1(HxStoragePutParam hxStoragePutParam, String condition, Long operateId) {
        return this.baseMapper.count1(hxStoragePutParam,condition,operateId);
    }

    @Override
    public List <HxStoragePutResult> listAll1(HxStoragePutParam hxStoragePutParam, String condition, Long operateId) {
        List<HxStoragePutResult> arrlist = this.baseMapper.listAll1(hxStoragePutParam,condition,operateId);
        return arrlist;
    }
}
